<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>编辑</title>
		<link rel="stylesheet" type="text/css" href="../../plugins/layui/css/layui.css" />
		<link href="../../kitAdmin/css/app.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" type="text/css" href="../../plugins/select2/dist/css/select2.min.css"/>
		<style type="text/css">
			/* .select2-container{
				display:none;
			} */

			/*.layui-unselect.layui-form-select {*/
				/*display: none;*/
			/*}*/
		</style>

	</head>

	<body>
		<div class='kit-table'>
			<div style='margin:10px'>
				<form class='layui-form' action='#' lay-filter='form-edit'>
					<input type='hidden' name='uniqueid' data-link='{:uniqueid}' />

					<div class='layui-inline'>
						<label class='layui-form-label'>选择学生</label>
						<div class="layui-input-block" style="width: 240px!important;">
							<select id='_studentId' name='studentId' lay-verify="required" lay-search="">
								<option value=""></option>

							</select>
						</div>
						<!-- <select data-link='{:studentId}' id='_studentId' name='studentId' class='layui-input'>
							<option value='请选择' selected="true">选择学生</option>
						</select> -->
					</div>

					<div class="layui-form-item">
						<label class='layui-form-label'>购买日期</label>
						<div class='layui-input-inline'>
							<input type='text' placeholder='' data-link='{:purchaseDate}' id='_purchaseDate' name='purchaseDate' class='layui-input'>
						</div>
					</div>

					<div class='layui-form-item'>
						<div class='layui-inline'>
							<label class='layui-form-label'>购买时长</label>
								<input type='hidden' placeholder='' data-link='{:hoursEnrolled}' id='_hoursEnrolled' name='hoursEnrolled' class='layui-input'>

							<!--<div class='layui-input-inline'>
								<input type='text' placeholder='' data-link='{:hoursEnrolled}' id='_hoursEnrolled' name='hoursEnrolled' class='layui-input'>
							</div>-->
							<div class="layui-input-inline" style="width: 80px;">
								<input type="text" data-link='{:hours}' id='_hours' placeholder="小时" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">小时</div>
							<div class="layui-input-inline" style="width: 80px;">
								<input type="text" data-link='{:minutes}' id='_minutes' placeholder="分钟" autocomplete="off" class="layui-input">
							</div>
							<div class="layui-form-mid">分钟</div>
						</div>
						<div class='layui-inline'>
							<label class='layui-form-label'>购买金额</label>
							<div class='layui-input-inline'>
								<input type='text' placeholder='' data-link='{:money}' id='_money' name='money' class='layui-input'>
							</div>
						</div>
					</div>
					<div class='layui-form-item'>
						<label class='layui-form-label'>负责人</label>
						<div class="layui-input-block" style="width: 240px!important;">
							<select id='_sellerId' name='sellerId' lay-verify="required" class="selectpicker">
								<option value=""></option>
							</select>
						</div>
					</div>
					<div class='layui-form-item'>
						<label class='layui-form-label'>付款方式</label>
						<div class="layui-input-block">
							<input type="radio" id="taobao" name="payMethod" value="淘宝付款" title="淘宝付款" checked>
							<input type="radio" id ="weixin" name="payMethod" value="微信付款" title="微信付款">
							<input type="radio" id ="zhuan" name="payMethod" value="转学生" title="转学生">
							<input type="radio" id="hui" name="payMethod" value="恢复上课" title="恢复上课">
							<input type="radio" id="qita" name="payMethod" value="其他" title="其他">
						</div>
					</div>
					<div class='layui-form-item'>
						<div class='layui-inline'>
							<label class='layui-form-label'>活动方式</label>
							<div class="layui-input-block">
								<input type="radio" id="putong" name="eventsWay" value="普通" title="普通" checked>
								<input type="radio" id="tuangou" name="eventsWay" value="团购" title="团购">
							</div>
						</div>
					</div>
					<div class='layui-form-item'>
						<label class='layui-form-label'>课程类型</label>
						<div class="layui-input-block">
							<input type="radio" id="xinbao" name="type" value="新报课程" title="新报课程" checked>
							<input type="radio" id ="xubao" name="type" value="续报课程" title="续报课程">
							<input type="radio" id="buke" name="type" value="补课时" title="补课时">
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block">
							<textarea id='_remark' name='remark' placeholder="请输入内容" class="layui-textarea"></textarea>
						</div>
					</div>

				</form>
			</div>
		</div>
		<script src="../../common/js/jquery.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../static/js/base.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../plugins/jsviews/jsviews.js" type="text/javascript"></script>
		<script src="../../plugins/layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../plugins/select2/dist/js/select2.min.js" type="text/javascript" charset="utf-8"></script>

		<script type="text/javascript">
            var purchaseCourseId = getQueryVariable('uniqueid');

            jQuery(document).ready(function() {
				init();
                $('select').select2().change();
            });

			var callback_save = function() {
				var hours=0;
				var minutes=0;
				if($('#_hours').val()){
					hours=$('#_hours').val();
				}
				if($('#_minutes').val()){
					minutes=$('#_minutes').val();
				}
				var total=parseInt(hours*60)+parseInt(minutes);
				$('#_hoursEnrolled').val(total);

				return $('.layui-form').serialize();
			}



            function studentsInfo() {
                var fuzerenSet = [];
                $.ajax({
                    url: baseUrl + '/students/select2',
                    type: 'get',
                    async: false,
                    success: function(data) {
                        fuzerenSet = data;
                        fuzerenSet.unshift({
                            // id : '请选择',
                            // text : '请选择'
                            id : 'all',
                            text : '请选择'
                        });

                        
                    },
                    error: function() {
                        //parent.layer.alert('加载学生信息出错！');
                    }
                });
                $('#_studentId').select2({
                    data : fuzerenSet
                });
            }

            function admins() {
                $.ajax({
                    url: baseUrl + '/admins',
                    type: 'get',
                    async: false,
                    success: function(data) {
                        var htm = "";
                        data = data.rows;
                        var arr = [];
                        for(var i = 0; i < data.length; i++) {
                            htm += '<option value="' + data[i].uniqueid + '">' + data[i].uname + '</option>';
                            var obj = {};
                            obj.id = data[i].studentId;
                            obj.text = data[i].enName + '  ' + data[i].zoomId;
                        }
                        $('#_sellerId').append(htm);
                    },
                    error: function() {
                        //parent.layer.alert('加载学生信息出错！');
                    }
                });
            }


            function purchaseCourseViews() {
                $.ajax({
                    url: baseUrl + '/purchaseCourseViews/id',
                    data:{
                        uniqueid:purchaseCourseId
                    },
                    type: 'get',
                    async: false,
                    success: function(data) {
                        // var htm = "";
                        // data = data.rows;
                        $.link(true, ".kit-table", data.data);

                        if(data.data.eventsWay!=null){
                            if(data.data.eventsWay=='普通'){
                                $("#putong").attr("checked", true)
                            }else{
                                $("#tuangou").attr("checked", true)
                            }
                        }

                        if(data.data.type!=null){
                            if(data.data.type=='新报课程'){
                                $("#xinbao").attr("checked", true)
                            }else if(data.data.type=='续报课程'){
                                $("#xubao").attr("checked", true)
                            }else {
                                $("#buke").attr("checked", true)
                            }
                        }

                        if(data.data.remark!=null){
                            $("#_remark").val(data.data.remark);
                        }

                        if (data.data.hoursEnrolled != null) {
                            var hour = parseInt(data.data.hoursEnrolled / 60);
                            var min = data.data.hoursEnrolled - hour * 60;
                            $("#_hours").val(hour);
                            $("#_minutes").val(min);
                        }

                        if (data.data.payMethod != null) {
                            if (data.data.payMethod == "淘宝付款") {
                                $("#taobao").attr("checked", true)
                            } else if (data.data.payMethod == "微信付款") {
                                $("#weixin").attr("checked", true)
                            } else if (data.data.payMethod == "转学生") {
                                $("#zhuan").attr("checked", true)
                            } else if (data.data.payMethod == "恢复上课") {
                                $("#hui").attr("checked", true)
                            } else if (data.data.payMethod == "其他") {
                                $("#qita").attr("checked", true)
                            }
                        }

                        // if (data.data.sellerId != null) {
                         //    var idl = data.data.sellerId;
                         //    $("#_sellerId").val(idl);
                        // }
                        //
                        //

                        // if(data.data.studentId!=null){
                         //    var idl = data.data.studentId;
                         //    $("#_studentId").val(idl);
						// }

                        $('select').select2().change();


                        // $('select').select2().change();
                        // var arr = [];
                        // for(var i = 0; i < data.length; i++) {
                        //     htm += '<option value="' + data[i].studentId + '">' + data[i].enName + '  ' + data[i].zoomId + '</option>'
                        //     var obj = {};
                        //     obj.id = data[i].studentId;
                        //     obj.text = data[i].enName + '  ' + data[i].zoomId;
                        // }
                        // $('#_studentId').append(htm);
                    },
                    error: function() {
                        //parent.layer.alert('加载学生信息出错！');
                    }
                });
            }
			function init() {
                studentsInfo();
                admins();
                purchaseCourseViews();

                $('#_studentId').change(function(){
                    alert($(this).children('option:selected').val());
                })
			}

			layui.use(['form', 'laydate'], function() {
				var form = layui.form;
				//监听提交
				form.on('submit(formDemo)', function(data) {
					layer.msg(JSON.stringify(data.field));
					return false;
				});
			});
		</script>
	</body>

</html>